package com.mhtvs;


import com.mhtvs.Database.PortForwards;
import com.mhtvs.Database.Servers;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

//---------------------------------------------------------------
//Development source for MHTVS CLIENT
//"Android client for use with MHTVS"
//Copyright (c) 2011, Doug Thompson, perladdict@gmail.com
//All rights reserved.
//
//http://code.google.com/p/mhtvs/
//
//View Demo here:
//http://www.youtube.com/watch?v=v4M2uVrMrGk
//
//Redistribution and use in source and binary forms, with or
//without modification, are permitted provided that the following
//conditions are met:
//
//* Redistributions of source code must retain the above
//  copyright notice, this list of conditions and the
//  following disclaimer.
//* Redistributions in binary form must reproduce the
//  above copyright notice, this list of conditions and
//  the following disclaimer in the documentation and/or
//  other materials provided with the distribution.
//* Neither the name of the developer nor the names
//  of its contributors may be used to endorse or promote
//  products derived from this software without specific
//  prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
//SUCH DAMAGE.
//---------------------------------------------------------------


// This class handles the creation and versioning of the application database

class DatabaseHelper extends SQLiteOpenHelper {
	
    private static final String DATABASE_NAME = "ssh_servers.db";
    private static final int DATABASE_VERSION = 1;
        
    
    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    
	@Override
	public void onCreate(SQLiteDatabase db) {		
		
		// CREATE SERVERS TABLE
		db.execSQL("CREATE TABLE " + Servers.SERVER_TABLE_NAME + " ( "
				+ Servers.SERVER_ID + " INTEGER PRIMARY KEY, " 
				+ Servers.SERVER_ADDRESS + " BLOB, " 
				+ Servers.SERVER_INTERNAL_ADDRESS + " BLOB, "
				+ Servers.SERVER_PAGE + " BLOB, "
				+ Servers.SERVER_USER + " BLOB, "		
				+ Servers.SERVER_PASSWORD + " BLOB, "
				+ Servers.SERVER_SALT + " BLOB, " 
				+ Servers.SERVER_PORT + " INTEGER, "	
				+ Servers.SERVER_DESCRIPTION + " BLOB, "
				+ Servers.SERVER_ACTIVE_STATE + " INTEGER, "
				+ Servers.SERVER_ACTIVE_INTERNAL_STATE + " INTEGER, "
				+ Servers.SERVER_PORTFORWARD_ID_KEY + " INTEGER )");

		// CREATE PORTFORWARDS TABLE
		db.execSQL("CREATE TABLE " + PortForwards.PORTFORWARDS_TABLE_NAME + " ( "
				+ PortForwards.PORTFORWARDS_ID + " INTEGER PRIMARY KEY, "
				+ PortForwards.PORTFORWARDS_ID_KEY + " INTEGER, "
				+ PortForwards.PORTFORWARDS_LOCAL + " INTEGER, "
				+ PortForwards.PORTFORWARDS_REMOTE + " INTEGER )");
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// Housekeeping here.
		// Implement how "move" your application data during an upgrade of schema versions		
		// There is no ALTER TABLE command in SQLite, so this generally involves
		// CREATING a new table, moving data if possible, or deleting the old data and starting fresh
		// Your call.
	}

	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
	}
}
